package org.gdkm.springbootxiangmushizhan.mapper;

import org.apache.ibatis.annotations.*;
import org.gdkm.springbootxiangmushizhan.domain.vo.CategoryAdminVO;
import java.util.List;
import java.util.Date;

@Mapper
public interface CategoryMapper {
    // 查询所有分类
    @Select("SELECT id, name, description, created, modified FROM t_category ORDER BY id DESC")
    List<CategoryAdminVO> selectAllCategories();

    // 按名称模糊查询分类
    @Select("SELECT id, name, description, created, modified FROM t_category WHERE name LIKE CONCAT('%',#{name},'%') ORDER BY id DESC")
    List<CategoryAdminVO> selectCategoriesByName(String name);

    // 新增分类
    @Insert("INSERT INTO t_category (name, description, created, modified) VALUES (#{name}, #{description}, #{created}, #{modified})")
    void insertCategory(@Param("name") String name, @Param("description") String description, @Param("created") Date created, @Param("modified") Date modified);

    // 编辑分类
    @Update("UPDATE t_category SET name=#{name}, description=#{description}, modified=#{modified} WHERE id=#{id}")
    void updateCategory(@Param("id") Integer id, @Param("name") String name, @Param("description") String description, @Param("modified") Date modified);

    // 删除分类
    @Delete("DELETE FROM t_category WHERE id=#{id}")
    void deleteCategory(Integer id);

    // 根据id查询单个分类
    @Select("SELECT id, name, description, created, modified FROM t_category WHERE id=#{id}")
    CategoryAdminVO selectCategoryById(Integer id);
} 